package com.my.demo;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;

/**
 * @description:
 * @author: marshal
 * @date: 2021-07-20 11:04 AM
 */
public class HelloJNA {
    // This is the standard, stable way of mapping, which supports extensive
    // customization and mapping of Java to native types.

    public interface CLibrary extends Library {
        CLibrary INSTANCE = (CLibrary)
                Native.load((Platform.isWindows() ? "msvcrt" : "c"),
                        CLibrary.class);

        void printf(String format, Object... args);
    }

    public static void main(String[] args) {
        int n = 10;
        String s = "abc";
        CLibrary.INSTANCE.printf("n=%d, s=%s \n", n, s);
//        for (int i = 0; i < args.length; i++) {
//            CLibrary.INSTANCE.printf("Argument %d: %s\n", i, args[i]);
//        }
    }
}
